package com.winston.proxy;

/**
 * created by winston on 2024/4/3
 */
public class StaticProxy {
    interface MessageSvc{
        void send(String msg);
    }

    static class SmsMessageSvc implements MessageSvc{

        @Override
        public void send(String msg) {
            System.out.println(SmsMessageSvc.class.getName() + ":  " + msg);
        }
    }

    static class MessageSvcProxy implements MessageSvc{
        private MessageSvc messageSvc;

        MessageSvcProxy(MessageSvc messageSvc) {
            this.messageSvc = messageSvc;
        }


        @Override
        public void send(String msg) {
            System.out.println("before");
            messageSvc.send(msg);
            System.out.println("after");
        }
    }

    public static void main(String[] args) {
        SmsMessageSvc smsMessageSvc = new SmsMessageSvc();
        MessageSvcProxy proxy = new MessageSvcProxy(smsMessageSvc);
        proxy.send("test msg");
    }
}
